import { BaseController, CoolController } from "@cool-midway/core";
import { Body, Inject, Post } from "@midwayjs/core";
import { CommentInfoEntity } from "../../entity/info";
import { CommentInfoService } from "../../service/info";
import { CommentInviteService } from "../../service/invite";
import { AddInviteCommentDTO, CommentListDTO, UserCommentPageDTO } from "../../dto/info";

@CoolController({
    api: ['list'],
    entity: CommentInfoEntity,
    service: CommentInfoService,
})
export class AppCommentInfoController extends BaseController {
    @Inject()
    commentInfoService: CommentInfoService;

    @Inject()
    commentInviteService: CommentInviteService;

    // @Post('/list', { summary: '根据关联信息获取评论列表' })
    // async list(@Body() body: CommentListDTO) {
    //     return this.ok(await this.commentInfoService.list(body.relatedId, body.relatedType));
    // }

    @Post('/detail', { summary: '根据邀请码获取服务人员详情' })
    async inviteDetail(@Body('inviteCode') inviteCode: string) {
        return this.ok(await this.commentInviteService.getInviteDetail(inviteCode));
    }

    @Post('/comment', { summary: '通过邀请码提交评论' })
    async inviteComment(@Body() body: AddInviteCommentDTO) {
        return this.ok(await this.commentInviteService.submitByInvite(body));
    }

    @Post('/myList', { summary: '获取我的评论列表' })
    async myList(@Body() body: UserCommentPageDTO) {
        return this.ok(await this.commentInfoService.myComments(body));
    }

    @Post('/relatedEntity', { summary: '根据关联类型获取实体' })
    async relatedEntity(@Body() body: CommentListDTO) {
        return this.ok(await this.commentInfoService.getRelatedEntity(body.relatedType, body.relatedId));
    }
}

